package com.my.roco.util;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class JdbcTest {
    public static void main(String[] args) {
        Properties properties = new Properties();
        try {
            // 使用类加载器加载资源流
            properties.load(JdbcTest.class.getClassLoader().getResourceAsStream("jdbc.properties"));
            
            String driverClassName = properties.getProperty("jdbc.driver");
            String url = properties.getProperty("jdbc.url");
            String username = properties.getProperty("jdbc.username");
            String password = properties.getProperty("jdbc.password");

            Class.forName(driverClassName);
            Connection connection = DriverManager.getConnection(url, username, password);
            System.out.println("数据库连接成功！");
            connection.close();
        } catch (IOException | ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }
    }
}